package dao

import (
	"context"
	"vben-admin/pkg/model"
	"vben-common/msdb"
	"vben-common/msdb/gorms"
)

type RoleButtonDao struct {
	conn *gorms.GormConn
}

func NewRoleButtonDao(db *msdb.MsDB) *RoleButtonDao {
	return &RoleButtonDao{
		conn: gorms.New(db.Conn),
	}
}

func (r *RoleButtonDao) CreateRoleButton(ctx context.Context, roleButton []*model.RoleButtonModel) error {
	db := r.conn.Session(ctx)
	db.Where("role_id = ?", roleButton[0].RoleId).Delete(&model.RoleButtonModel{})

	db = r.conn.Session(ctx)
	err := db.Create(roleButton).Error
	return err
}

func (r *RoleButtonDao) GetRoleButtonList(ctx context.Context, roleId int64) ([]*model.RoleButtonModel, error) {
	var roleButtonList []*model.RoleButtonModel
	err := r.conn.Session(ctx).Where("role_id = ?", roleId).Find(&roleButtonList).Error
	return roleButtonList, err
}
